<?php
namespace plugins\site_config\controller;
use cmf\controller\ApiThirdAccessBaseController;
use plugins\site_config\model\SiteConfigHpcModel;
use plugins\site_config\lib\Common as LCOM;

class ApiHomePageController extends ApiThirdAccessBaseController
{
    //获取首页配置信息
    public function getHomePageConfig()
    {
        $param = $this->request->param();
        
        $type = isset( $param [ 'type' ] ) ? $param [ 'type' ] : 'none' ; 
        $page = isset( $param [ 'page' ] ) ? $param [ 'page' ] : 1;
        $pageSize = isset( $param [ 'limit' ] ) ? $param [ 'limit' ] : 20 ; 
        
        if( !in_array( $type , [ 0,1,2,3] ) || $type == 'none' ){
            
            return api_json_echo( false , '请传入正确的参数数据' );
        }
        
        $list = SiteConfigHpcModel::where( 'type' , $type )->where( 'status' , 1 )->order( 'list_order' )->paginate( $pageSize , false , [ 'query'=>[ 'pageSize'=>$pageSize,'page'=>$page] ] )->each( function( $item ){
            if( !empty( $item [ 'image' ] ) ){
                $item [ 'image' ] = zy_domain().$item [ 'image' ];
            }
            return $item;
        } );
        return api_json_echo( true, '成功' , $list );
        
    }

    /**
     * 获取网站信息
     */    
    public function getSiteInfo()
    {
        $info = \plugins\setting\lib\Setting::getCache( 'site_config' );
        //$info = LCOM::getSiteInfo();
        if( isset( $info [ 'logo' ] ) ){
            $info [ 'logo' ] = isset( $info [ 'logo' ] ) ? zy_domain().$info [ 'logo' ] : '';
        } 
        return api_json_echo( true , '成功' , $info );
    }
    
}